<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>crypto-js-demo</title>
    <script src="http://cdn.staticfile.org/crypto-js/3.1.2/components/core-min.js"></script>
    <!-- <script src="http://cdn.staticfile.org/crypto-js/3.1.2/components/md5-min.js"></script> 
    <script src="http://cdn.staticfile.org/crypto-js/3.1.2/components/rc4-min.js"></script> -->

   <script src="http://cdn.staticfile.org/crypto-js/3.1.2/components/cipher-core-min.js"></script>
    <script src="https://cdn.staticfile.org/crypto-js/3.1.2/components/mode-ecb.js"></script>
    <script src="https://cdn.staticfile.org/crypto-js/3.1.2/components/enc-base64.js"></script>

    <script src="https://cdn.staticfile.org/crypto-js/3.1.2/rollups/tripledes.js"></script>
</head>

<body>
    <script>
        // //MD5
        // var md5Str = CryptoJS.MD5("key").toString(CryptoJS.enc.Hex).toUpperCase();
        // console.log("md5后得到的字符串：%s", md5Str)
        // //使用md5后的字符串作为rc4的加密密钥实现rc4加解密
        // var key = CryptoJS.enc.Utf8.parse(md5Str);
        // var encryStr = CryptoJS.RC4.encrypt("测试", key).toString();
        // console.log("rc4加密后得到的字符串：%s", encryStr)
        // var decryptStr = CryptoJS.RC4.decrypt(CryptoJS.lib.CipherParams.create({
        //     ciphertext: CryptoJS.enc.Hex.parse(encryStr)
        // }), key).toString(CryptoJS.enc.Utf8);
        // console.log("rc4解密后得到的字符串：%s", decryptStr);

        //des
        var keyHex = CryptoJS.enc.Utf8.parse("12345678");
        console.log("keyHex", keyHex.toString(CryptoJS.enc.Utf8));

        var info = "geffzhang";
        console.log("info", info)
        //console.log(CryptoJS);
        var encrypted = CryptoJS.DES.encrypt(info, keyHex, {
            mode: CryptoJS.mode.ECB,
            padding: CryptoJS.pad.Pkcs7
        });
        console.log("encrypted", encrypted.toString());

        var decrypted = CryptoJS.DES.decrypt(encrypted, keyHex, {
            mode: CryptoJS.mode.ECB,
            padding: CryptoJS.pad.Pkcs7
        });
        console.log("decrypted", decrypted.toString(CryptoJS.enc.Base64 ))
    </script>
</body>

</html>